<?php
/**
 * Created by PhpStorm.
 * User: zhaojia
 * Date: 15-9-16
 * Time: 下午4:16
 */
class Xinwen extends CI_Model{

    public function __construct(){
        parent::__construct();
        $this->load->database();
        $this->load->model('Xinwen');

    }

    public function get_data($id=NULL,$limit=NULL){

            if($id==NULL){
                if($limit=NULL){
                    $query=$this->db->order_by('addtime','DESC')->get('news')->result_array();
                    return $query;
                }{
                    $query=$this->db->order_by('addtime','DESC')->get('news','10',$limit)->result_array();
                    return $query;
                }

            }else{
                $data=$this->db->where(array('id'=>$id))->get('news')->result_array();
                return $data[0];
            }
    }

    public function add_data($data){
        $this->db->insert('question',$data);

    }

    public function save_data($data,$id){
        $this->db->where(array('id'=>$id))->update('news',$data);

    }

    public function del_data($id){
        $this->db->where(array('id'=>$id))->delete('news');

    }
}